<?php require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
require_once($GLOBALS['PAD']."Modules/RHUSJW24/modconf.mex"); 
MYTCONN();
	$MYT = $GLOBALS['MYT'];
	$MD = 'ED';
	
	if (isset($_GET['RSID'])) {
		$GET = $GLOBALS['MYT']->db_array("SELECT * FROM systemoffice.main_users 
				LEFT OUTER JOIN systemoffice.timeclock_profiles ON UserID = ref
				WHERE ref = {$_GET['RSID']}");
	} else {
		$Values = $GLOBALS['MYT']->db_array("DESCRIBE systemoffice.main_users");
		for($a=1;$a<=$Values[0];$a++) {
			$field = $Values[$a]['Field'];
			$GET[1][$field] = '';
				if ($field == 'last_login') {
				$GET[1][$field] = 0;
				}
				if ($field == 'Type') {
				$GET[1][$field] = 2;
				}
		}
		$Values = $GLOBALS['MYT']->db_array("DESCRIBE systemoffice.timeclock_profiles");
		for($a=1;$a<=$Values[0];$a++) {
			$field = $Values[$a]['Field'];
			$GET[1][$field] = '';
		}
	} 
	if ($GET[1]['Type'] == 5) {
	$MD = 'RD';
	}
	$Qr = "SELECT ttk_ID AS ID, CONCAT('Entre ',entrytime,' e as ',leavetime,' Almo&ccedilo: ',lunchstart,' ',lunchend) AS NAME
		FROM systemoffice.timeclock_ttables
		ORDER BY entrytime,leavetime";
	mn_field('hidden','ED','ref',$GET[1]['ref'],'','','',''); 
	?>

<table width="100%"  border="0" cellpadding="0" cellspacing="3" bgcolor="#F2F2F2">
<tr bgcolor="#F2F2F2">
          <td colspan="3"><b>Funcionario</b><?php 
		  if ($GET[1]['ref'] == 0) {
		  echo 'Atribuido a funcionario: ';
		  $qr_Staff = "SELECT smb_ID AS ID, smb_Name AS NAME FROM systemoffice.staff_members WHERE smb_Flag = 2";
		  mn_field('select',$MD,'StaffMember',$GET[1]['StaffMember'],$qr_Staff,' - Escolher - ','',''); 
		  echo ' | ';
		  mn_field('button',$MD,'new_StaffMember','Novo Funcionario','','','',''); 
		  } else {
		  echo $GET[1]['name'];
		  mn_field('hidden','ED','StaffMember',$GET[1]['StaffMember'],'','','',''); 
		  } ?></td>
  </tr>
  <tr>
	<td colspan="3"> 
		<div class="Line">
		<b>Permiss&otilde;es</b>
		<table>
		<tr>
		<?php 
			$get_Modules = $GLOBALS['MYT']->db_array("SELECT * FROM systemoffice.administration_modules WHERE modFlag = 2");
			mn_field('hidden','ED','tot_modules',$get_Modules[0],'','','','');
			$crr_Modules = explode(';',$GET[1]['modules_ref']);
			for ($i=1;$i<=$get_Modules[0];$i++) {
			if (!isset($crr_Modules[$i-1]))  { $crr_Modules[$i-1] = 0;}
			echo '<td>'.$get_Modules[$i]['label'].'</td><td>';
				mn_field('hselect','ED','mod_'.$get_Modules[$i]['ref'],substr($crr_Modules[$i-1],strlen($crr_Modules[$i-1])-1,1),";ADMIN;GEST;BOUSER;REPORT;USER#0;A;G;B;R;N",'','','');
			echo '</td>';
			
				if ($i%4==0) {
				echo '</tr><tr>';
				}
			} ?>
		</tr>
		</table>
		</div>
	</td>
  </tr>
		<tr>
			<td>
			<div class="Line"><b>Horario</b></td>
			<td>
			<table>
			<tr><td>2. F</td><td><?php mn_field('select','ED','upr_Day1',$GET[1]['upr_Day1'],$Qr,' Folga ','',''); 
						mn_field('button','ED','set_multifield',' = ','','','','" onclick="
							$i = 1;
							while($i<=5) {
							document.getElementById(\'upr_Day\'+$i).value=document.user_form.upr_Day1.value;
							$i++;
							}');?></td></tr>
			<tr><td>3. F</td><td><?php mn_field('select','ED','upr_Day2',$GET[1]['upr_Day2'],$Qr,' Folga ','',''); ?></td></tr>
			<tr><td>4. F</td><td><?php mn_field('select','ED','upr_Day3',$GET[1]['upr_Day3'],$Qr,' Folga ','',''); ?></td></tr>
			<tr><td>5. F</td><td><?php mn_field('select','ED','upr_Day4',$GET[1]['upr_Day4'],$Qr,' Folga ','',''); ?></td></tr>
			<tr><td>6. F</td><td><?php mn_field('select','ED','upr_Day5',$GET[1]['upr_Day5'],$Qr,' Folga ','',''); ?></td></tr>
			<tr><td>Sab.</td><td><?php mn_field('select','ED','upr_Day6',$GET[1]['upr_Day6'],$Qr,' Folga ','',''); ?></td></tr>
			<tr><td>Dom.</td><td><?php mn_field('select','ED','upr_Day0',$GET[1]['upr_Day0'],$Qr,' Folga ','',''); ?></td></tr>
			
			</table>
			</div>
			</td>
			<td>
			<div class="Line"><b>Acesso</b>
			<table>
			<tr bgcolor="#F2F2F2"><td>Dominio:</td><td><?php 
		  $OriDM = "SELECT ref AS ID, name AS NAME FROM systemoffice.main_offices WHERE type IN (1,2)";
		  mn_field('select',$MD,'ref_office',$GET[1]['ref_office'],$OriDM,'','False',''); ?></td></tr>
        <tr bgcolor="#F2F2F2"><td>Grupo:</td><td><?php 
		  $Groups = "SELECT sug_ID AS ID, sug_Name AS NAME FROM systemoffice.sys_usergroups WHERE sug_Flag = 1";
		  mn_field('select',$MD,'usr_UserGroup',$GET[1]['usr_UserGroup'],$Groups,'','False',''); ?></td></tr>
        <tr bgcolor="#F2F2F2"><td>Utilizador:</td><td><?php 
		  mn_field('text',$MD,'username',$GET[1]['username'],'25','25','',''); ?></td></tr>
        <tr bgcolor="#F2F2F2">
          <td>Password:</td><td><div id="ResetPassword"><?php 
		  mn_field('button',$MD,'password','Redefenir Password','25','25','','" onClick="
		  	if(confirm(\'Tem a certeza que pretende apagar a password deste utilizador?\')==true) {
			
				document.user_form.action=\''.$MODURL.'Lib/pr_users.php?act=4&RSID='.$GET[1]['ref'].'\';
				subform(\'user_form\',\'ResetPassword\');
			
			}'); ?></div></td>
        </tr>
        <tr bgcolor="#F2F2F2"><td bgcolor="#F2F2F2">Criação:</td><td><?php $GET[1]['last_login']; ?></td></tr>
        <tr bgcolor="#F2F2F2"><td bgcolor="#F2F2F2">Ultimo Acesso:</td><td><?php date("Y-m-d H:i:s",$GET[1]['last_login']); ?></td></tr>
        <tr bgcolor="#F2F2F2"><td bgcolor="#F2F2F2">Desactivacao:</td><td><?php $GET[1]['last_login']; ?></td></tr>
		<tr bgcolor="#F2F2F2">
          <td>Estado:</td>
          <td><?php 
		  $OriST = "Activo;Suspenso;Eliminado#2;3;5";
		  mn_field('hselect',$MD,'OriST',$GET[1]['Type'],$OriST,'','False',''); ?></td>
        </tr>
		</table>
			</div>		
			</td>
		</tr>
    </table>
<?php
	if ($GET[1]['Type'] == 2) {
 mn_field('button',$MD,'Save','Guardar','','','','" style="width:45%" onClick="
	document.user_form.action=\''.$MODURL.'Lib/pr_users.php?act=1&RSID='.$GET[1]['ref'].'\';
	subform(\'user_form\',\'pr_user\');');
	if ($GET[1]['ref'] > 0) {
 mn_field('button',$MD,'Save','Desactivar','','','','" style="width:45%" onClick="
	document.user_form.action=\''.$MODURL.'Lib/pr_users.php?act=2&RSID='.$GET[1]['ref'].'\';
	subform(\'user_form\',\'pr_user\');');
	}
	}
	if ($GET[1]['Type'] == 5) {
	echo '<div id="Msg" class="Alert">Este utilizador encontra-se desactivado.</div>';
 mn_field('button','ED','Save','Reactivar','','','','" style="width:45%" onClick="
	document.user_form.action=\''.$MODURL.'Lib/pr_users.php?act=3&RSID='.$GET[1]['ref'].'\';
	subform(\'user_form\',\'pr_user\');');
	} ?>
<div id="pr_user"></div>